package com.li.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.li.mapper.ClueMapper;
import com.li.mapper.ClueRecordMapper;
import com.li.pojo.dto.ClueDTO;
import com.li.pojo.po.Clue;
import com.li.pojo.po.PageResult;
import com.li.service.ClueRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClueRecordServiceImpl implements ClueRecordService {

    @Autowired
    private ClueRecordMapper clueRecordMapper;
    @Autowired
    private ClueMapper clueMapper;

    @Override
    public void recordAdd(Clue clue) {
        ClueDTO clueDTO = new ClueDTO();
        BeanUtils.copyProperties(clue,clueDTO);
        clueDTO.setCreateBy("admin");
        clueDTO.setCreateTime(LocalDateTime.now().toString().replace("T"," "));
        clueRecordMapper.recordAdd(clueDTO);
        clueMapper.modifyClu(clue);
    }

    @Override
    public PageResult recordList(Long id, Integer pageSize, Integer pageIndex) {
        PageHelper.startPage(pageIndex,pageSize);
        Page<ClueDTO> page = clueRecordMapper.recordList(id,pageIndex,pageSize);
        PageResult result = new PageResult();
        Object params = result.getParams();
        return new PageResult(200,"查询成功",params,page.getResult(),page.getTotal());
    }
}
